<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="/WEB-INF/html.tld" prefix="html"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>

<c:url var="applicantUrl" value="/application/add" />
<c:url var="applicationSubSectionUrl" value="/application/add/subsection" />
<c:url var="productSelectionUrl" value="/application/productSelection" />
<c:url var="applicationSubmissionUrl" value="/application/applicationSubmission" />

<div class="window">
	<div class="window-holder">
		<h4 class="window-header-title"><span>Application Entry Form</span></h4>
		<div class="window-content">
			<div class="breadcrumb green">
				<a href="javascript:_loadContent('${applicationSubSectionUrl}','applicationForm')" class="active">Applicant Details</a>
				<a href="javascript:_loadContent('${productSelectionUrl}','applicationForm')" class="dependent">Product and Financed</a>
				<a href="javascript:_loadContent('${applicationSubmissionUrl}','applicationForm')"  class="dependent">Application Submission</a>
			</div>
			
			<div id="window-content-holder">
				<jsp:include page="applicationSection.jsp" />
			</div>
		</div>
		<div class="window-footer-title">
		<div class="button-holder">
			
			<button type="button" onClick="submitForm();" id="valdateAndSave">Validate And Save</button>
		</div>
	</div>
	</div>
</div>	
		
<script type="text/javascript">
<!--
$(function(){
	
	//$(".dependent").attr('disable',true);
	//$('.dependent').bind('click', false);
	
});
function submitForm()
{
	//$('.amount').inputmask('remove');
	//TODO:put below lines inside the doAjaxMethod. and explain what does it means.
	jQuery.ajaxSettings.traditional = true;
	//$("#applicationForm").valid();
	var formData = $("#applicationForm").serializeObject();
	//formData.rateCards=assignedRate;

	var params={url:"${applicantUrl}",success:onSuccess,data:formData,type:"POST",dataType:"json"};
	doAjax(params);
}



function onSuccess(result)
{
	console.log(result);
	console.log(result.objectName);
 	$("input[name='"+result.objectName+"']").val(result.objectId);
 	/* if(result.objectId!=null && result.objectId!='')
 	$('.dependent').bind('click', true); */
 	//TODO:ajax error rendering put it on common place
 	$( result.fieldError).each(function() {
		console.log(this.field);
		$('input[name="'+this.field+'"]').css( "border",'1px solid red' );
	});
}

//-->
</script>
